function latticePaths(n) {
    let dp = [];
    for (let i = 0; i <= n; i++)
        dp.push(new Array(n + 1));
    for (let i = 0; i <= n; i++) {
        dp[i][0] = dp[0][i] = 1;
    }
    for (let i = 1; i <= n; i++)
        for (let j = 1; j <= n; j++) {
            dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
        }
    return dp[n][n];
}

console.log(latticePaths(4));